package com.dwf.dominion;
import com.dwf.dominion.Card.Category;;

public class Rule {
	public enum RuleComparison {GREATER_THAN,LESS_THAN,EQUAL_TO};
	public int requiredMinimum;
	public int requiredMaximum;
	public Category requiredCategory;
	public Card reqSpecificCard;
	public boolean requirementSatisfied;
	public int conditionMinimum;
	public int conditionMaximum;
	public Category conditionCategory;
	public Card condSpecificCard;
	public boolean conditionSatisfied;
	
	public int requirementCount;
	public int conditionCount;
	
	public Rule(int min, int max, Category cat)
	{
		this.requiredMinimum = min;
		this.requiredMaximum = max;
		this.requiredCategory = cat;
		this.conditionCategory = null;
		this.conditionSatisfied = true;
		this.requirementSatisfied = false;
	}
	
	public Rule(int min, int max, Category cat, int minCondition, int maxCondition, Category catCondition)
	{
		this.requiredMinimum = min;
		this.requiredMaximum = max;
		this.requiredCategory = cat;
		this.conditionMinimum = minCondition;
		this.conditionMaximum = maxCondition;
		this.conditionCategory = catCondition;
		this.conditionSatisfied = false;
		this.requirementSatisfied = false;
	}
	
	public Rule (int min, int max, Category cat, Card cardCondition)
	{
		this.requiredMinimum = min;
		this.requiredMaximum = max;
		this.requiredCategory = cat;
		this.conditionCategory = Category.SPECIFIC_CARD;
		this.condSpecificCard = cardCondition;
		this.conditionSatisfied = false;
		this.requirementSatisfied = false;
	}

	public Rule (Card cardRequired, Card cardCondition)
	{
		this.requiredCategory = Category.SPECIFIC_CARD;
		this.reqSpecificCard = cardRequired;
		this.conditionCategory = Category.SPECIFIC_CARD;
		this.condSpecificCard = cardCondition;
		this.conditionSatisfied = false;
		this.requirementSatisfied = false;
	}

	public Rule (Card cardRequired, int minCondition, int maxCondition, Category catCondition)
	{
		this.requiredCategory = Category.SPECIFIC_CARD;
		this.reqSpecificCard = cardRequired;
		this.conditionMinimum = minCondition;
		this.conditionMaximum = maxCondition;
		this.conditionCategory = catCondition;
		this.conditionSatisfied = false;
		this.requirementSatisfied = false;
	}
	
	public boolean satisfiesRequirement (Card card)
	{
		if (this.requiredCategory == Category.SPECIFIC_CARD)
		{
			if (card.equals(this.reqSpecificCard))
				return true;
			else
				return false;
		}
		if (card.isCategory(this.requiredCategory))
			return true;
		else
			return false;
	}
	
	public boolean satisfiesCondition (Card card)
	{
		if (this.conditionCategory == Category.SPECIFIC_CARD)
		{
			if (card.equals(this.condSpecificCard))
				return true;
			else
				return false;
		}
		if (card.isCategory(conditionCategory))
			return true;
		else
			return false;
	}
	
	public String toString()
	{
		String output = "Require ";
		
		if (requiredCategory == Category.SPECIFIC_CARD)
		{
			output += this.reqSpecificCard.name;
		}
		else
		{
			if (this.requiredMinimum != 0)
			{
				output += "at least " + String.valueOf(this.requiredMinimum) + " ";
				if (this.requiredMaximum != 10)
				{
					output += "but";
				}
			}
			if (this.requiredMaximum != 10)
			{
				output += "fewer than " + String.valueOf(this.requiredMaximum) + " ";
			}
			output += this.requiredCategory.toString();
		}
		
		if (conditionCategory == Category.SPECIFIC_CARD)
		{
			output += " if " + this.condSpecificCard.name + " is selected.";
		}
		else if (conditionCategory != null)
		{
			output += " if there are ";
			if (this.conditionMinimum != 0)
			{
				output += "at least " + String.valueOf(this.conditionMinimum) + " ";
				if (this.conditionMaximum != 10)
				{
					output += "but";
				}
			}
			if (this.conditionMaximum != 10)
			{
				output += "fewer than " + String.valueOf(this.conditionMaximum) + " ";
			}
			output += this.conditionCategory.toString() + ".";
		}
		else
			output += ".";
		
		return output;
	}
}
